package com.power.using.askapp.fragment;

import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.baoyachi.stepview.VerticalStepView;
import com.google.gson.Gson;
import com.power.using.askapp.R;
import com.power.using.askapp.base.BaseMainFragment;
import com.power.using.askapp.bean.ProgressBean;
import com.power.using.askapp.http.HttpApi;
import com.power.using.askapp.http.Request;
import com.power.using.askapp.utils.HttpUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by 聪明一只哈 on 2018/5/25.
 * Time: 2018/5/25  10:35
 */

public class TwoFrament extends BaseMainFragment {


    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    Unbinder unbinder;
    @BindView(R.id.step_view)
    VerticalStepView stepView;
    @BindView(R.id.refreshLayout)
    SwipeRefreshLayout refreshLayout;
    //private String dealprogress;
    private List<String> list0;
    private String dealprogress1="";

    public static TwoFrament newInstance() {

        Bundle args = new Bundle();

        TwoFrament fragment = new TwoFrament();
        fragment.setArguments(args);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_two, container, false);
        unbinder = ButterKnife.bind(this, view);

        initView(view);
        return view;
    }

    private void initView(View view) {
        toolbarTitle.setText("受理查看");
        list0 = new ArrayList<>();
        list0.add("您已提交问题，等待系统确认");
        list0.add("您的问题已被确认");
        list0.add("您的问题已被受理");
        list0.add("请您对处理过程进行评价");
        list0.add("评价完毕,感谢您的支持");



    }


    //懒加载

    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        super.onLazyInitView(savedInstanceState);
        initData();
        initListener();
    }

    private void initData() {
        HttpUtils.requestGet(_mActivity, HttpApi.GET_STEP, new Request(){
            @Override
            public void success(String result) {
                super.success(result);
                Log.i("show", "success: "+result);
                ProgressBean homeBean = new Gson().fromJson(result, ProgressBean.class);
                if(homeBean.getCode()==200){

                    dealprogress1 = homeBean.getDealprogress();
                    Toast.makeText(getActivity(), "提交问题成功", Toast.LENGTH_SHORT).show();
                    initStepView();


                }
            }

            @Override
            public void error(String error) {
                super.error(error);
                Log.i("show", "error: "+error);
            }
        });
    }

    private void initListener() {
        //下拉刷新
        refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        initData();

                        refreshLayout.setRefreshing(false);
                    }
                },2000);

            }
        });
    }

    private int flag = 0;

    private void initStepView() {
        switch (dealprogress1) {
            case "":
            case "1":
            case "2":
                flag = 2;
                break;
            case "3":
                flag = 3;
                break;
            case "4":
                flag = 4;
                break;
            case "5":
                flag = 6;
                break;

        }
        stepView.setStepsViewIndicatorComplectingPosition(flag-1)//设置完成的步数
                .reverseDraw(false)//default is true
                .setTextSize(14)
                .setStepViewTexts(list0)//总步骤
                //完成后的实线
                .setStepsViewIndicatorCompletedLineColor(ContextCompat.getColor(getActivity(), android.R.color.white))//设置StepsViewIndicator完成线的颜色
                //未完成的虚线
                .setStepsViewIndicatorUnCompletedLineColor(ContextCompat.getColor(getActivity(), R.color.uncompleted_text_color))//设置StepsViewIndicator未完成线的颜色
                //已完成的文字
                .setStepViewComplectedTextColor(ContextCompat.getColor(getActivity(), android.R.color.white))//设置StepsView text完成线的颜色
                //未完成的文字
                .setStepViewUnComplectedTextColor(ContextCompat.getColor(getActivity(), R.color.uncompleted_text_color))//设置StepsView text未完成线的颜色
                //
                .setStepsViewIndicatorCompleteIcon(ContextCompat.getDrawable(getActivity(), R.drawable.complted))//设置StepsViewIndicator CompleteIcon
                //
                .setStepsViewIndicatorDefaultIcon(ContextCompat.getDrawable(getActivity(), R.drawable.default_icon))//设置StepsViewIndicator DefaultIcon
                //
                .setStepsViewIndicatorAttentionIcon(ContextCompat.getDrawable(getActivity(), R.drawable.attention));//设置StepsViewIndicator AttentionIcon
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


}
